/*
 * Process.h
 *
 *  Created on: Mar 9, 2012
 *      Author: Dan
 */

#ifndef PROCESS_H_
#define PROCESS_H_
#include <pthread.h>

//Enum for System Calls
enum SystemCall {
	SYS_IO = 1,
	SYS_SEM_DOWN = 2,
	SYS_SEM_UP = 3,
	SYS_MEM_RW = 4
} SystemCall;
//End System Calls

//Process
typedef struct Process {
	int	instructions;	// number of time steps before resetting to 0 - number of instructions
	int request_at;	//instruction line where a request is made
	int request;// The type of system call this process performs.
						// time step. These are the synchronous events that result in traps being issued.
	int next_PC;		// this is the step count that the CPU had gotten to when this process was
						// paused (like a PC register value)
	int state;			// e.g. 0=running, 1=ready, 2=interrupted, 3=blocked
	int id;
} Process;
void initializeProducerProcess(Process* c);
void initializeConsumerProcess(Process* c);
void initializeCalculatorProcess(Process* c);
void initializeKeyboardProcess(Process* c);
//end Proces

//Memory
typedef struct SharedMemory {
	int memory1, memory2;
	int locked;
} SharedMemory;

void mem1Up(SharedMemory* m);
void mem1Down(SharedMemory* m);
int mem2Read(SharedMemory* m);
void mem2Write(SharedMemory* m, int val);
int isLocked(SharedMemory* m);
//end Memory

//Devices IO
void* runKeyboard(int* kbio); //TODO add pointer to here and blow in params that can be constantly checked for a call
void* runAux(int* auxio);
void pause();
//end Devices IO

//Scheduler
typedef struct Scheduler {
	int CurrentProcess;
	int type;
	Process *my_processes[4];
} Scheduler;
void initializeScheduler(Scheduler* s, int t, Process *p[]);
Process* getNext(Scheduler* s);
Process* getCurrent(Scheduler* s);
//end Scheduler

//SystemTimer
typedef struct SystemTimer {
	int interval;
	int interrupted;
	pthread_t systhread;
} SystemTimer;
void* runTimer(SystemTimer* c);
void initializeSystemTimer(SystemTimer* c, int interval);
//end SystemTimer

#endif /* PROCESS_H_ */
